package com.macro.mall.tiny.modules.ums.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.macro.mall.tiny.common.api.CommonPage;
import com.macro.mall.tiny.common.api.CommonResult;
import com.macro.mall.tiny.modules.ums.model.MeetingRoom;
import com.macro.mall.tiny.modules.ums.model.UmsRole;
import com.macro.mall.tiny.modules.ums.service.MeetingRoomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 会议室表 前端控制器
 * </p>
 *
 * @author macro
 * @since 2024-04-11
 */
@Controller
@Api(tags = "MeetingRoomController")
@Tag(name = "MeetingRoomController",description = "会议室管理")
@RequestMapping("/meetingRoom")
public class MeetingRoomController {
    @Autowired
    private MeetingRoomService meetingRoomService;

    @ApiOperation("获取所有会议室")
    @RequestMapping(value = "/listAll", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<List<MeetingRoom>> listAll() {
        List<MeetingRoom> meetingRoomList = meetingRoomService.list();
        return CommonResult.success(meetingRoomList);
    }

    @ApiOperation("添加会议室")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult create(@RequestBody MeetingRoom meetingRoom) {
        boolean success = meetingRoomService.create(meetingRoom);
        if (success) {
            return CommonResult.success(null);
        }
        return CommonResult.failed();
    }
    @ApiOperation("根据角色名称分页获取会议室列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<CommonPage<MeetingRoom>> list(@RequestParam(value = "keyword", required = false) String keyword,
                                                  @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                  @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        Page<MeetingRoom> roleList = meetingRoomService.list(keyword, pageSize, pageNum);
        return CommonResult.success(CommonPage.restPage(roleList));
    }

    @ApiOperation("修改会议室")
    @RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult update(@PathVariable Long id, @RequestBody MeetingRoom meetingRoom) {
        meetingRoom.setId(id);
        boolean success = meetingRoomService.updateByMeetingId(meetingRoom);
        if (success) {
            return CommonResult.success(null);
        }
        return CommonResult.failed();
    }

    @ApiOperation("修改会议室")
    @RequestMapping(value = "/updateStatus/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult updateStatus(@PathVariable Long id, @RequestParam(value = "status") Integer status) {
        MeetingRoom meetingRoom = new MeetingRoom();
        meetingRoom.setId(id);
        meetingRoom.setStatus(status);
        boolean success = meetingRoomService.updateById(meetingRoom);
        if (success) {
            return CommonResult.success(null);
        }
        return CommonResult.failed();
    }

    @ApiOperation("删除指定会议室")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult delete(@PathVariable Long id) {
        boolean success = meetingRoomService.delete(id);
        if (success) {
            return CommonResult.success(null);
        }
        return CommonResult.failed();
    }
}

